package cn.lingyangwl.agile.auth.model.rqrs.ldp;

import cn.afterturn.easypoi.excel.annotation.Excel;
import cn.afterturn.easypoi.excel.annotation.ExcelCollection;
import cn.afterturn.easypoi.excel.annotation.ExcelIgnore;
import cn.hutool.core.collection.CollUtil;
import cn.lingyangwl.agile.model.ExcelBaseModel;
import cn.lingyangwl.agile.model.constants.ValidationCons;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;

import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import java.io.Serializable;
import java.util.List;

/**
 * 身份源 excel 表格
 * @author shenguangyang
 */
@Getter
@Setter
public class ExtLdpExcel extends ExcelBaseModel {
    @ExcelIgnore
    private Long id;

    @Excel(name = "编码", width = 30)
    @NotEmpty(message = ValidationCons.NOT_EMPTY)
    private String code;

    @Excel(name = "类型", width = 20)
    @NotEmpty(message = ValidationCons.NOT_EMPTY)
    private String type;

    @Excel(name = "名称", width = 20)
    @NotEmpty(message = ValidationCons.NOT_EMPTY)
    private String name;

    @Excel(name = "图标", width = 20)
    private String logo;

    @Excel(name = "描述", width = 20)
    private String description;

    @Excel(name = "备注", width = 20)
    private String remark;

    @ExcelCollection(name = "登录模式")
    @Valid
    private List<Connect> connectList;

    @Data
    public static class Connect implements Serializable {
        @ExcelIgnore
        private Long id;

        @Excel(name = "授权方式", width = 25)
        @NotEmpty(message = ValidationCons.NOT_EMPTY)
        private String grantType;

        @Excel(name = "场景", width = 25)
        @NotEmpty(message = ValidationCons.NOT_EMPTY)
        private String scenes;

        @Excel(name = "名称", width = 25)
        @NotEmpty(message = ValidationCons.NOT_EMPTY)
        private String name;

        @Excel(name = "图标", width = 25)
        private String logo;

        @Excel(name = "是否隐藏", width = 25)
        private Boolean isHidden;

        @Excel(name = "标识", width = 25)
        @NotEmpty(message = ValidationCons.NOT_EMPTY)
        private String code;

        @Excel(name = "描述", width = 30)
        private String description;

        @Excel(name = "是否询问绑定", width = 30)
        private Boolean isAskBind;

        @Excel(name = "显示名称", width = 30)
        private String displayName;

        @Excel(name = "配置key", width = 30)
        private String configKey;
    }

    public void removeEmptyConnect() {
        if (CollUtil.isEmpty(this.connectList)) {
            return;
        }
        Connect connect = this.connectList.get(0);
        if (StringUtils.isAllEmpty(connect.code, connect.name, connect.displayName)) {
            this.connectList.remove(0);
        }
    }
}
